﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Moonwish.Silverlight.OsAvatar.Utility
{
    /// <summary>
    /// 开始程序菜单树菜单项边距转换器。
    /// by zhlin 2011-12-04
    /// </summary>
    public class MarginFormatter : IValueConverter
    {
        // Methods
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                var left = 0;
                var p = (Programs.ProgramWrapper) value;
                var parent = p.Parent;
                while (parent != null)
                {
                    left += 32;
                    parent = parent.Parent;
                }
                return new Thickness(left, 0, 0, 0);
            }
            catch (Exception)
            {
                return value;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
